﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Data;

public class ActorManager
{

    private static ActorManager _instance;
    public static ActorManager Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new ActorManager();
            }
            return _instance;
        }
    }

    public Account localUser;
    public List<Account> otherUsers;

    public Tank localTank;
    public Dictionary<string, Tank> tanks = new Dictionary<string, Tank>();

    //判断是否是本机玩家
    public bool IsLocalUser(string username)
    {
        return localUser.username == username;
    }

    //添加tank
    public void AddTank(string username, Tank tank)
    {
        tanks.Add(username, tank);
        if (username == localUser.username)
        {
            localTank = tank;
        }
    }

    //删除tank
    public void RemoveTank(string username)
    {
        if (tanks.ContainsKey(username))
        {
            Tank tank = tanks[username];
            tank.OnDead();
            tanks.Remove(username);
        }
    }

    //获取tank
    public Tank GetTank(string username)
    {
        if (tanks.ContainsKey(username))
        {
            return tanks[username];
        }
        return null;
    }
}
